home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Text / Digest-Browser-1.6 Folder / Views / CDisplayIndex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-16  |  5.0 KB  |  262 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.     CDisplayIndex.c
  3.     
  4.     Methods for a text list with selectable lines.
  5.         
  6.     Copyright © 1989 Symantec Corporation. All rights reserved.
  7.     Copyright © 1991 Manuel A. Pérez.  All rights reserved.
  8.  
  9.  ******************************************************************************/
  10.  
  11.  
  12. #include "CDisplayIndex.h"
  13. #include <Commands.h>
  14. #include <CDocument.h>
  15. #include <CBartender.h>
  16. #include <Constants.h>
  17. #include "Global.h"
  18. #include <string.h>
  19. #include "BrowserCmds.h"
  20.  
  21. /*** Global Variables ***/
  22. extern    CBartender    *gBartender;
  23. extern EventRecord  gLastMouseUp;
  24.  
  25. /***
  26.  *
  27.  * IDisplayIndex
  28.  *
  29.  ***/
  30.  
  31. void CDisplayIndex::IDisplayIndex(CView *anEnclosure, CBureaucrat *aSupervisor,
  32.         short vLoc, short vHeight, BrowserDirPtr theDir, long index_displayed)
  33. {
  34.  
  35.     inherited::ISelectLine(anEnclosure, aSupervisor, vLoc, vHeight);
  36.     itsDir = theDir;
  37.     itsSelItem = NULL;
  38.  
  39. // JRB addition - geneva looks better
  40.     SetSelection( 0, 32767, false);
  41.     SetFontNumber(geneva);
  42.     SetFontSize(10);
  43. // END JRB addition
  44.  
  45.  
  46.     SetIndex(index_displayed);
  47. }
  48.  
  49. /***
  50.  *
  51.  * SetIndex
  52.  *
  53.  *    Build a text handle with the information for the index list, and
  54.  *    stuff it into the TE item.
  55.  *
  56.  ***/
  57.  
  58. void    CDisplayIndex::SetIndex(long index_displayed)
  59. {
  60. BrowserItemPtr p;
  61. long    offset;
  62. long    totalSize;
  63. short    len;
  64. Handle    data;
  65. char *a;
  66. long i, selLine;
  67.  
  68.     // as part of the initialization process, check how much
  69.     // data we have in the header, create a handle and copy
  70.     // it there.
  71.  
  72.     totalSize = 0;
  73.     for (p = itsDir->topItem; p != NULL; p = brGetNext(p))
  74.         switch (index_displayed) {
  75.             case cmdIndexFrom:
  76. //following line deleted by JRB
  77. //            default:
  78.                 totalSize += strlen(p->from) + 1;        // 1 is for new line
  79.                 break;
  80.             case cmdIndexDate:
  81.                 totalSize += strlen(p->date) + 1;        // 1 is for new line
  82.                 break;
  83.             case cmdIndexSubject:
  84.                 totalSize += strlen(p->subject) + 1;        // 1 is for new line
  85.                 break;
  86. // JRB addition - new subject line option
  87.             default:
  88.             case cmdIndexComposite:
  89.                 totalSize += strlen(p->composite) + 1;
  90.                 break;
  91. // end JRB
  92.         }
  93.  
  94.     FailNIL(data = NewHandle(totalSize));
  95.     HLock(data);
  96.     offset = 0;
  97.     for (p = itsDir->topItem; p != NULL; p = brGetNext(p)) {
  98.         switch (index_displayed) {
  99.             case cmdIndexFrom:
  100. // following line deleted by JRB
  101. //            default:
  102.                 a = p->from;
  103.                 break;
  104.             case cmdIndexDate:
  105.                 a = p->date;
  106.                 break;
  107.             case cmdIndexSubject:
  108.                 a = p->subject;
  109.                 break;
  110. // JRB addition - new subject line option
  111.             default:
  112.             case cmdIndexComposite:
  113.                 a = p->composite;
  114.                 break;
  115. // end JRB addition
  116.         }
  117.         len = strlen(a);
  118.         BlockMove(a, (*data)+offset, len);
  119.         offset += len;
  120.         (*data)[offset++] = '\r';        // TE new line
  121.     }
  122.     (*data)[--offset] = ' ';            // remove the last new line
  123.     HUnlock(data);
  124.     SetTextHandle(data);
  125.     DisposHandle(data);
  126.  
  127.     // Now that we have store the text in the TE item, lets restore the
  128.     // marked items.
  129.  
  130.     // Save the currently selected line            
  131.     selLine = GetSelectedLine();
  132.  
  133.     // set all the old tags
  134.     for (i = 0, p = itsDir->topItem; p != NULL; i++, p = brGetNext(p))
  135.         if (brGetMark(p))    // if it was already on
  136.             TagLine(i, true, false, false);
  137.  
  138.     // Setting the selected line back to what it was
  139.     SetSelectedLine(selLine, true);
  140. }
  141.  
  142. /***
  143.  *
  144.  * Dispose
  145.  *
  146.  ***/
  147. void CDisplayIndex::Dispose(void)
  148. {
  149. BrowserItemPtr p, q;
  150.  
  151.     // release memory occupied by link list
  152.     for (p = itsDir->topItem; p != NULL;) {
  153.         q = brGetNext(p);
  154.         Deallocate(p);
  155.         p = q;
  156.     }
  157.     itsDir->topItem = NULL;
  158.  
  159.     // and close file
  160.     fclose(itsDir->fp);
  161.     inherited::Dispose();
  162.  
  163. }
  164.  
  165. /***
  166.  * 
  167.  * SelectionChanged
  168.  *
  169.  * Called after the selection may have changed to notify dependants.
  170.  *
  171.  ***/
  172.  
  173. void CDisplayIndex::SelectionChanged(void)
  174. {
  175. register BrowserItemPtr p;
  176. long i;
  177.  
  178.     // find item
  179.     p  = itsDir->topItem;
  180.     for (i = 0; i != selLine && p; i++)
  181.         p = brGetNext(p);
  182.  
  183.     BroadcastChange(textSelectionChanged, (void *)p);
  184. }
  185.  
  186. /***
  187.  *
  188.  * TagLine(long line, Boolean setSelection, Boolean redraw)
  189.  *
  190.  ***/
  191. void CDisplayIndex::TagLine(long line, Boolean tag, Boolean setSelection, Boolean redraw)
  192. {
  193. long i, selLine;
  194.  
  195.  
  196.     if (setSelection) {
  197.         SetSelectedLine(line, redraw);
  198.         SetFontStyle(bold);
  199.         brSetMark(itsSelItem, tag);    // itsSelItem set by SetSelectedLine
  200.     }
  201.     else {
  202.         // Save the currently selected line            
  203.         selLine = GetSelectedLine();
  204.  
  205.         SetSelectedLine(line, false);
  206.         SetFontStyle(bold);
  207.         brSetMark(itsSelItem, tag);
  208.  
  209.         // Setting the selected line back to what it was
  210.         SetSelectedLine(selLine, true);
  211.     }
  212. }
  213.  
  214. /***
  215.  *
  216.  * SetSelectedLine
  217.  *
  218.  ***/
  219. void CDisplayIndex::SetSelectedLine( long line, Boolean redraw)
  220. {
  221. register BrowserItemPtr p;
  222. long i;
  223.  
  224.     inherited::SetSelectedLine(line, redraw);
  225.  
  226.     // find item
  227.     p  = itsDir->topItem;
  228.     for (i = 0; i != selLine && p; i++)
  229.         p = brGetNext(p);
  230.     itsSelItem = p;
  231. }
  232.  
  233. /***
  234.  *
  235.  * TagItem
  236.  *
  237.  ***/
  238. void CDisplayIndex::TagItem(void)
  239. {
  240.     SetFontStyle(bold);
  241.     brToggleMark(itsSelItem);
  242. }
  243.  
  244. /***
  245.  *
  246.  * GetSelectedItem
  247.  *
  248.  ***/
  249. BrowserItemPtr CDisplayIndex::GetSelectedItem(void)
  250. {
  251.     return itsSelItem;
  252. }
  253.  
  254. /***
  255.  *
  256.  * GetDirectory
  257.  *
  258.  ***/
  259. BrowserDirPtr CDisplayIndex::GetDirectory(void)
  260. {
  261.     return itsDir;
  262. }